const express = require("express")
const blogRouter = express.Router()

const blogSevr = require("../../services/blogServices")

blogRouter.put("/addBlog", async(req,res,next)=>{
    try {
        const result = await blogSevr.addBlog(req.body)
        if(result){
            res.send(result)
        }
        console.log(req.body)
    } catch (error) {
        next(error)
    }
})

blogRouter.get("/getBlog", async(req,res,next)=>{
    try {
        const result = await blogSevr.getBlog()
        if(result){
            res.send(result)
        }
    } catch (error) {
        next(error)
    }
})

blogRouter.post("/bokeDetails", async(req,res,next)=>{
    try {
        const result = await blogSevr.bokeDetails(req.body)
        if(result){
            res.send(result)
        }
    } catch (error) {
        next(error)
    }
})

blogRouter.get("/blogDetails", async(req,res,next)=>{
    try {
        const result = await blogSevr.bokeDetails(req.query)
        if(result){
            res.send(result)
        }
    } catch (error) {
        next(error)
    }
})

blogRouter.get("/search", async(req,res,next)=>{
    try {
        const result = await blogSevr.search(req.query)
        if(result){
            res.send(result)
        }
    } catch (error) {
        next(error)
    }
})

module.exports = blogRouter